package com.yd.controller.yd;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.yd.pojo.Users;
import com.yd.service.UsersService;
import com.yd.tool.UtsReg;


@Controller
public class UsersControllerYD {

	@Resource
	private UsersService usersService;

	

	@RequestMapping(value={"/app/users/token/getusers"})
	@ResponseBody
	public String app_users_token_getusers(HttpServletRequest request) {
		JSONObject jsonObject = new JSONObject();

		String key = "";
		String token = "";
		if (UtsReg.getStringKB(request.getParameter("key"))){key = request.getParameter("key").trim();} else {jsonObject.put("msg","key错误");jsonObject.put("error", "1");return jsonObject.toString();}
		if (UtsReg.getStringKB(request.getParameter("token"))){token = request.getParameter("token").trim();} else {jsonObject.put("msg","token错误");jsonObject.put("error", "1");return jsonObject.toString();}
		
		if(!key.equals("yydd")){
			jsonObject.put("msg","key不正确");jsonObject.put("error", "1");return jsonObject.toString();
		}
		
		Users users=usersService.selectOne(new EntityWrapper<Users>().eq("token", token));
		if(users==null){
			jsonObject.put("msg","token不正确");jsonObject.put("error", "1");return jsonObject.toString();
		}
		
		users.setLoginpass("");

		jsonObject.put("data",users);
		jsonObject.put("msg", "成功");
		jsonObject.put("error", "0");
		return jsonObject.toString();
	}
	
	
	@RequestMapping(value={"/app/users/uid/getusers"})
	@ResponseBody
	public String app_users_uid_getusers(HttpServletRequest request) {
		JSONObject jsonObject = new JSONObject();

		String key = "";
		String uid = "";
		if (UtsReg.getStringKB(request.getParameter("key"))){key = request.getParameter("key").trim();} else {jsonObject.put("msg","key错误");jsonObject.put("error", "1");return jsonObject.toString();}
		if (UtsReg.getIntXl(request.getParameter("uid"))){uid = request.getParameter("uid").trim();} else {jsonObject.put("msg","UID错误1");jsonObject.put("error", "1");return jsonObject.toString();}
		
		if(!key.equals("yydd")){
			jsonObject.put("msg","key不正确");jsonObject.put("error", "1");return jsonObject.toString();
		}
		
		Users users=usersService.selectOne(new EntityWrapper<Users>().eq("id", uid));
		if(users==null){
			jsonObject.put("msg","token不正确");jsonObject.put("error", "1");return jsonObject.toString();
		}
		
		users.setLoginpass("");

		jsonObject.put("data",users);
		jsonObject.put("msg", "成功");
		jsonObject.put("error", "0");
		return jsonObject.toString();
	}
	
	
	
}


















